﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.DistributedServices.PermisosModule.Resources;

namespace Cesave.DistributedServices.PermisosModule
{
    /// <summary>
    /// Excepción de autentificación.
    /// </summary>
    public class AuthenticationException
        : ApplicationException
    {

        #region Private properties

        private string _customMessage;

        private AuthenticationResult _authenticationResult;

        #endregion

        #region Public properties

        public string CustomMessage
        {
            get
            {
                return _customMessage;
            }
            set
            {
                _customMessage = value;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public AuthenticationException()
        {
        }

        /// <summary>
        /// Constructor para indicar el mensaje personalizado.
        /// </summary>
        /// <param name="customMessage">
        /// Mensaje personalizado.
        /// </param>
        public AuthenticationException(string customMessage)
        {
            _customMessage = customMessage;
        }

        /// <summary>
        /// Constructor para indicar el resultado de la autentificación.
        /// </summary>
        /// <param name="authenticationResult">
        /// Resultado de la autentificación.
        /// </param>
        public AuthenticationException(AuthenticationResult authenticationResult)
        {
            _authenticationResult = authenticationResult;
            switch (_authenticationResult)
            {
                case AuthenticationResult.LoginFailed:
                    _customMessage = Messages.exception_LoginFailed;
                    break;
                case AuthenticationResult.UserNotFound:
                    _customMessage = Messages.exception_UserNotFound;
                    break;
                case AuthenticationResult.WrongPassword:
                    _customMessage = Messages.exception_WrongPassword;
                    break;
                default:
                    break;
            }
            CustomMessage = _customMessage;
        }

        #endregion

    }
}
